/*
 * 
 * LegendShop 多用户商城系统
 * 
 *  版权所有,并保留所有权利。
 * 
 */
package com.legendshop.oa.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import com.legendshop.framework.controller.BaseController;
import com.legendshop.oa.constants.PathResolver;
import com.legendshop.oa.handler.AttachmentManager;
import com.legendshop.oa.model.SystemConfig;
import com.legendshop.oa.pages.AdminTilesPage;
import com.legendshop.oa.pages.RedirectPage;
import com.legendshop.oa.service.SystemConfigService;
import com.legendshop.oa.tag.ResourceBundleHelper;

/**
 * 系统配置控制器
 *
 */
@Controller
@RequestMapping("/admin/system/systemConfig")
public class SystemConfigController extends BaseController {
	
	@Autowired
	private SystemConfigService systemConfigService;

	@Autowired
	private AttachmentManager attachmentManager;

	/**
	 * 保存系统配置
	 * @param request
	 * @param response
	 * @param systemConfig
	 * @return
	 */
	@RequestMapping(value = "/save")
	public String save(MultipartHttpServletRequest request, HttpServletResponse response, SystemConfig systemConfig) {
		SystemConfig originSystemConfig = systemConfigService.getSystemConfig();
		originSystemConfig.setIcpInfo(systemConfig.getIcpInfo());
		originSystemConfig.setUrl(systemConfig.getUrl());
		originSystemConfig.setSupportMail(systemConfig.getSupportMail());

		systemConfigService.updateSystemConfig(originSystemConfig);
		saveMessage(request, ResourceBundleHelper.getSucessfulString());
		return PathResolver.getPath(request, response, RedirectPage.SYSTEM_CONFIG_QUERY);
	}

	/**
	 * 加载全局配置页面
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/load")
	public String load(HttpServletRequest request, HttpServletResponse response) {
		SystemConfig systemConfig = systemConfigService.getSystemConfig();
		request.setAttribute("systemConfig", systemConfig);
		return PathResolver.getPath(request, response, AdminTilesPage.SYSTEMCONFIG_EDIT_PAGE);
	}

}
